﻿using System;

namespace GenericMethod
{
    class Program
    {
        static void Main(string[] args)
        {
            ClassWithGenericMethod classWithGenericMethod = new ClassWithGenericMethod();
            int t1 = 100;
            int t2 = 200;
            Console.WriteLine($"交换之前数值t1数值{t1},t2数值{t2}");
            classWithGenericMethod.Swap<int>(ref t1, ref t2);
            Console.WriteLine($"交换之后数值t1数值{t1},t2数值{t2}");

            string s1 = "Hello";
            string s2 = "World";
            Console.WriteLine($"字符串交换前S1{s1},S2{s2}");
            classWithGenericMethod.Swap(ref s1, ref s2);
            Console.WriteLine($"字符串交换后S1{s1},S2{s2}");
        }


    }

    public class ClassWithGenericMethod
    {
        //泛型方法,获取交换后的T1,T2
        public void Swap<T>(ref T t1, ref T t2)
        {
            T temp;
            temp = t1;
            t1 = t2;
            t2 = temp;

        }
    }
}
